/** 根据数据字典英文名称查询数据字典信息[返回字典项列表]
 * @param dictEanem
 * @return Array
 */
export function getDictItemByEname(dictEname, type) {
	let result = []
	let str = uni.getStorageSync('sysDictItemMap')
	if (!str) return result
	let sysDictItemMap = JSON.parse(str)
	for (let key in sysDictItemMap) {
		let item = sysDictItemMap[key]
		if (item.dictEname === dictEname) {
			result.push(item)
		}
	}
	if (!type || type === 'asc') {
		result.sort(compareAsc('hardCode'))
	} else {
		result.sort(compareDesc('hardCode'))
	}

	return result
}

// 获取国家列表
export function getCountryList() {
	let result = []
	let str = uni.getStorageSync('countryMap')
	if (!str) return result
	let countryMap = JSON.parse(str)
	for (let key in countryMap) {
		let item = countryMap[key]
		result.push(item)
	}
	return result
}

/**
 * json对象数组按照某个属性排序:降序排列
 * @param {Object} propertyName
 */
function compareAsc(propertyName) {
  return function(object1, object2) {
    var value1 = object1[propertyName]
    var value2 = object2[propertyName]
    if(!value1 || !value2) {
      return 0
    }
    if(value1 < value2) {
      return -1
    } else if(value1 > value2) {
      return 1
    } else {
      return 0
    }
  }
}
/**
 * json对象数组按照某个属性排序:升序排列
 * @param {Object} propertyName
 */
function compareDesc(propertyName) {
  return function(object1, object2) {
    var value1 = object1[propertyName]
    var value2 = object2[propertyName]
    if(!value1 || !value2) {
      return 0
    }
    if(value1 < value2) {
      return 1
    } else if(value1 > value2) {
      return -1
    } else {
      return 0
    }
  }
}